<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
    :dialogWidth="dialogWidth"
  >
    <template #searchPanel>
      <search-panel
        :addPer="'wash:save'"
        :selectPer="'wash:page'"
        :excelPer="'admin'"
        addTitle="新增洗车单"
        @insert="add"
        @search="search"
        @export="handleDataExport('Wash','工单数据')"
        :showSearchButton="true"
        :showAddButton="true"
        :showExportButton="true"
      >
        <job-shop v-model="searchOptions.storeId" placeholder="所属门店" />
        <el-select clearable v-model="searchOptions.status" placeholder="状态">
          <el-option
            v-for="item in types['工单状态']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="searchOptions.likeName"
          clearable
          placeholder="工单编号/客户手机号/客户姓名/车牌"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        @row-dblclick="rowDblclick"
      >
        <template #action="{ row }">
          <i
            class="el-icon-s-order"
            title="工单"
            style="cursor: pointer"
            @click="handleDataUpdateEdit(row, '工单')"
          ></i>
          <i
            class="el-icon-edit marginLeft"
            title="编辑"
            style="cursor: pointer"
            v-permission="'wash:update'"
            @click="handleDataUpdateEdit(row, '编辑')"
          ></i>
          <i
            class="el-icon-delete marginLeft"
            title="删除"
            style="color: red; cursor: pointer"
            v-permission="'wash:del'"
            @click="handleDataDelete(row)"
          ></i>
        </template>
      </data-table>
    </template>

    <template #dialog>
      <dialog-view-detail
        :workOrderId="selectRow.id"
        :workOrderType="2"
        @close="dialogCloseEv"
      />
    </template>
  </base-layout>
</template>
<script>
import { washList, deleteWash } from "@/api/after-sale/workOrderManage/car-wash";
import baseMixin from "@/mixins/base";
import DialogViewDetail from "../view/index.vue";
import { JobShop } from "@/components/index";
import { getDict } from "@/utils";
export default {
  components: { JobShop, DialogViewDetail },
  mixins: [
    baseMixin({
      findData: washList,
      deleteData: deleteWash,
      dataName: ["content", "totalRecords"],
      isAdd: false,
      // findDataById: getRapidById,
      // updateData: editRapid,
      idName: "id",
    }),
  ],
  data() {
    return {
      dialogWidth: "1200px",
      dialogVisible: false,
      tableColumnAttributes: [
        { name: "所属门店", value: "storeName", type: "text" },
        { name: "工单编号", value: "workOrderCode", type: "text" },
        { name: "单据日期", value: "receiptsTime", type: "text" },
        { name: "车牌号", value: "licensePlateNumber", type: "text" },
        { name: "客户姓名", value: "clientName", type: "text" },
        { name: "性别", value: "genderCst", type: "text" },
        { name: "客户联系方式", value: "phone", type: "text" },
        { name: "项目总数", value: "projectNumber", type: "text" },
        { name: "接待人员", value: "receptionName", type: "text" },
        { name: "预计交车时间", value: "predictDeliveryDate", type: "text" },
        { name: "付款状态", value: "payStatus", type: "text" },
        { name: "状态", value: "status", type: "text" },
        { name: "当前作业项目", value: "currentProjectName", type: "text" },
        { name: "当前作业人员", value: "currentUserName", type: "text" },
        { name: "工单总金额", value: "amount", type: "text" },
        { name: "工单备注", value: "remark", type: "text" },
        { name: "录入时间", value: "createTime", type: "text" },
      ],
      types: {},
      selectRow: {},
    };
  },
  async created() {
    this.types = getDict(["工单状态"]);
  },
  methods: {
    search(form) {
      // this.searchOptions = { ...form };
      this.currentPage = 1;

      this.setTableData();
    },
    dialogCloseEv() {
      this.dialogClose();
      this.setTableData();
    },
    rowDblclick(row) {
      this.selectRow = row;
      this.dialogVisible = true;
      this.dialogTitle = "工单详情";
      // this.handleDataChange(row,'工单详情')
    },
    add() {
      this.$router.push({ path: "/workOrderManage/create-car-wash" });
    },
    handleDataUpdateEdit(row, type) {
      if (type == "编辑") {
        this.$router.push({
          name: "eidtCarWashOrder",
          params: { id: row.id },
        });
      } else if (type == "工单") {
        this.$router.push({
          name: `simplicityOrder`,
          params: { id: row.id, type: 2 },
        });
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.marginLeft {
  margin-left: 10px;
}
</style>
